home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 3.4 KB | 123 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/16/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPPeriodicTask
-
- SUPERCLASS: CPPObject
-
- This C++ class is an abstract class for objects which
- perform some periodic action.
-
- ********************************************************************/
-
-
- #include <CPPPeriodicTask.h>
- #include <CPPTaskManager.h>
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPPeriodicTask::CPPPeriodicTask (CPPTaskManager *TaskManager,
- long minPeriod,
- Boolean deleteWhenCompleted)
- {
- this->minimumPeriod = minPeriod;
- this->lastCalled = -32767; // so we will be called immediately
- this->timesCalled = 0; // just because we're interested
- this->hasCompleted = TRUE;
- this->deleteWhenDone = deleteWhenCompleted;
- this->ourManager = TaskManager;
- this->completion = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPPeriodicTask::~CPPPeriodicTask (void)
- {
- // if we are still busy, remove us from our manager's queue
- if (this->ourManager && (!this->hasCompleted))
- this->ourManager->RemovePeriodicTask(this, FALSE);
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPPeriodicTask::ClassName (void)
- {
- return "CPPPeriodicTask";
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPPeriodicTask::GetPeriod (void)
- /* accessor function for the period variable */
- {
- return this->minimumPeriod;
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPPeriodicTask::GetTimesCalled (void)
- /* accessor function for the period variable */
- {
- return this->timesCalled;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPPeriodicTask::SetPeriod (long newPeriod)
- /* setter function for the period variable */
- {
- this->minimumPeriod = newPeriod;
- // force it to run immediately
- this->lastCalled = -32767;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPPeriodicTask::NeedsToRun (void)
- /* returns TRUE if the minimum period for this task has passed */
- {
- if (TickCount() - this->lastCalled > this->minimumPeriod)
- return TRUE;
- else
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- OSErr CPPPeriodicTask::TaskError (void)
- /* Accessor function for the error code returned by the last op. */
- {
- return this->callResult;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPPeriodicTask::SetCompletionProc (CompletionProc NewProc)
- /* set a special routine to be run when the task completes */
- {
- this->completion = NewProc;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPPeriodicTask::DoPeriodicAction (void)
- /* Do bookkeeping; subclass should override w/ something useful */
- {
- this->lastCalled = TickCount();
- this->timesCalled++;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPPeriodicTask::DoCompletedAction (void)
- /* execute the completion routine, if there is one */
- {
- if (this->completion)
- (*this->completion)((CPPObject *)this);
- }
-
- /*-----------------------------------------------------------------*/
-